﻿using System.Web.UI;
using JQuery.WebKit.Base;

[assembly: WebResource("JQuery.WebKit.JInput.JInput.js", "text/javascript")]
[assembly: WebResource("JQuery.WebKit.JInput.JInput.min.js", "text/javascript")]

namespace JQuery.WebKit
{
    public class JInput : JControl
    {
        internal override PostType PostType { get { return PostType.Value; } }
        public InputType InputType { get; set; }

        public int TextAreaRows { get; set; }
        public int TextAreaCols { get; set; }

        public JInput() : base("input") { }
        public JInput(string tag) : base("input") { }

        protected override void Render(HtmlTextWriter writer)
        {
            if (!base.Width.IsEmpty)
            {
                this.Style.Add(HtmlTextWriterStyle.Width, base.Width.ToString());
            }
            switch (InputType)
            {
                case InputType.Text:
                    this.Attributes.Add("type", "text");
                    break;
                case InputType.TextArea:
                    base.TagName = "textarea";
                    this.Attributes.Add("cols", TextAreaCols > 0 ? TextAreaCols.ToString() : "10");
                    this.Attributes.Add("rows", TextAreaRows > 0 ? TextAreaRows.ToString() : "10");
                    this.Attributes.Add("style", "width: 100%");
                    break;
                case InputType.Password:
                    this.Attributes.Add("type", "password");
                    break;
                default:
                    break;
            }
            this.Attributes.Add("name", this.ClientID);
            base.Render(writer);
        }
        protected override void CreateChildControls()
        {
            //base.CreateChildControls();
        }
    }
}
